unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

const
  N=4;


type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  arr : array [0..N*N-1] of TButton;


implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i, j, t : integer;
begin
  for i :=0 to N*N-1 do
  for t := 0 to N-1 do
    begin
      for j:=0 to N-1 do
        begin
        arr[i] := TButton.Create(Form1);
        arr[i].Parent := Form1;
        arr[i].Width := 50;
        arr[i].Height := 50;
        arr[i].Top :=t*50;
        arr[i].Left := j*50;
        arr[i].OnClick := Button2Click;
  end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i : integer;
begin
  for i := 0 to N*N-1 do
  begin
    if (Sender = arr[i]) then
    begin
      arr[i].Caption := 'Test';
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
end;

end.
